package com.zhiziai.aiproxy.dto;

import com.zhiziai.aiproxy.constants.BusinessCode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: liuxinyu06
 * @description:
 * @create: 2021-09-01
 **/

public class JsonVo {
    private Object data;
    private String msg;
    private int code;

    public JsonVo(Object data) {
        this.data = data;
        this.code = BusinessCode.SUCCESS.getValue();
    }

    public JsonVo(int code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    public JsonVo(int code, String msg, Object data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public JsonVo addData(String name, Object value) {
        if (this.data == null || !(this.data instanceof Map)) {
            this.data = new HashMap();
        }

        ((Map) this.data).put(name, value);
        return this;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getCode() {
        return this.code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getData() {
        return this.data;
    }
}
